1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| // // 6209 제자리 멀리뛰기 이분탐색.cpp // Algorithm // // Created by bbvch13531 on 2018. 3. 30.. // Copyright © 2018년 bbvch13531. All rights reserved. // #define MAX_D 1000000000 #include <iostream> #include <cstdio> #include <algorithm>
using namespace std;
bool solve(int);
int D,N,M,in[50010]={0,};
int main(void){ int lb,ub,x; scanf("%d %d %d",&D,&N,&M); for(int i=0;i<N;i++){ scanf("%d",&in[i+1]); } in[0]=0; in[N+1]=D; lb=0; ub=MAX_D; sort(in,in+N+2); while (lb<ub) { x=(lb+ub+1)/2; if(solve(x)) lb=x; else ub=x-1; } printf("%d",ub); return 0; }
bool solve(int x){ int cur=0,cnt=0; for(int i=1;i<N+2;i++){ if(cur+x>in[i]) cnt++; else cur=in[i]; } return (cnt<=M && cur==D); }
|